﻿using System;
using winS.Unity.Process;
using winS.Unity.Serialization;

namespace winS.UnityEditor.ProcessEditor
{
    /// <summary>
    /// Provides process asset management in UnityEditor.
    /// </summary>
    public static class EditorProcessAssetManager
    {
        private static readonly Serializer serializer = new Serializer();
        private static readonly Deserializer deserializer = new Deserializer();

        public static string NewGUID()
        {
            return Guid.NewGuid().ToString("N");
        }

        public static void Create<T>(string path) where T : IProcess, new()
        {
            T newProcess = new T();
            newProcess.startStep.guid = NewGUID();
            serializer.Serialize(newProcess, path);
        }
        public static void Save(EditorProcessInfo editorProcessInfo)
        {
            serializer.Serialize(editorProcessInfo.process, EditorAssetManager.ProjectPathToFullPath(editorProcessInfo.pathRelativeProject));
            EditorAssetManager.Refresh();
        }
        public static IProcess LoadFromString(string content)
        {
            return deserializer.Deserialize<IProcess>(content);
        }
        public static IStep StringToStep(string data)
        {
            return deserializer.Deserialize<IStep>(data);
        }
        public static string StepToString(IStep step)
        {
            return serializer.Serialize(step);
        }
    }
}